#include "Renderer_PCH.h"

/*--------------------------------------------------------------------------*/

GLenum ToEnum(const std::string& s)
{
	static std::map<std::string, GLenum> map;
	static bool initialized = false;

	if (!initialized)
	{
		initialized = true;

		map["repeat"] = GL_REPEAT;
		map["clamp"] = GL_CLAMP;
		map["clamptoedge"] = GL_CLAMP_TO_EDGE;

		map["linear"] = GL_LINEAR;
		map["nearest"] = GL_NEAREST;
		map["linear_mipmap_linear"] = GL_LINEAR_MIPMAP_LINEAR,
		map["nearest_mipmap_linear"] = GL_NEAREST_MIPMAP_LINEAR,
		map["linear_mipmap_nearest"] = GL_LINEAR_MIPMAP_NEAREST,

		map["one"] = GL_ONE;
		map["zero"] = GL_ZERO;
		map["src_alpha"] = GL_SRC_ALPHA;
		map["one_minus_src_alpha"] = GL_ONE_MINUS_SRC_ALPHA;
		map["funcadd"] = GL_FUNC_ADD;

		map["ccw"] = GL_CCW;
		map["cw"] = GL_CW;

		map["front"] = GL_FRONT;
		map["back"] = GL_BACK;
		map["frontandback"] = GL_FRONT_AND_BACK;
		map["none"] = GL_NONE;

		map["fill"] = GL_FILL;
		map["line"] = GL_LINE;
		map["point"] = GL_POINT;

		map["true"] = GL_TRUE;
		map["false"] = GL_FALSE;

		map["lequal"] = GL_LEQUAL;
	}

	auto iter = map.find(s);

	if (iter == map.end())
	{
		__Crash("Unknown enum: %s", s.c_str());
		return GL_FALSE;
	}
	else
	{
		return iter->second;
	}
}